package com.citcc.business.service;

import com.citcc.business.bean.*;
import com.citcc.business.mapper.ActivityResourcesEntityMapper;
import com.citcc.business.mapper.TCdzSerTypeInfoMapper;
import com.citcc.business.mapper.TCdzSerTypeModuleMapper;
import com.citcc.business.mapper.VersionInfoEntityMapper;
import com.citcc.business.util.CollectionUtil;
import com.citcc.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * creat_user: 秦波
 * describe: TODO
 **/
@Service
public class H5Service  {
    @Autowired
    private TCdzSerTypeInfoMapper appSerTypeEntityMapper;
    @Autowired
    private TCdzSerTypeModuleMapper serModuleEntityMapper;
    @Autowired
    private ActivityResourcesEntityMapper activityResourcesEntityMapper;
    @Autowired
    private VersionInfoEntityMapper versionInfoEntityMapper;

    public List<TCdzSerTypeInfo> findAll(String type,String appSource,String orgCode) {
        TCdzSerTypeInfo tCdzSerTypeInfo=new TCdzSerTypeInfo();
        tCdzSerTypeInfo.setType(type);
        tCdzSerTypeInfo.setShowFlag("1");
        tCdzSerTypeInfo.setDelFlag("0");
        List<TCdzSerTypeInfo> appSerTypeEntities = appSerTypeEntityMapper.selectTCdzSerTypeInfoList(tCdzSerTypeInfo);
        return appSerTypeEntities;
    }

    public List<TCdzSerTypeModule> findModel(String id, String appSource, String orgCode) {

        TCdzSerTypeModule tCdzSerTypeModule=new TCdzSerTypeModule();
        tCdzSerTypeModule.setSerId(id);
        tCdzSerTypeModule.setShowFlag("1");
        tCdzSerTypeModule.setDelFlag("0");
        List<TCdzSerTypeModule> serModuleEntities = serModuleEntityMapper.selectTCdzSerTypeModuleList(tCdzSerTypeModule);
        return serModuleEntities;
    }

    public List<ActivityResourcesEntity> findH5resourcess(String type) {
        ActivityResourcesEntityExample activityResourcesEntityExample = new ActivityResourcesEntityExample();
        ActivityResourcesEntityExample.Criteria criteria = activityResourcesEntityExample.createCriteria();
        criteria.andDelFlagEqualTo("0");
        criteria.andStateEqualTo("1");
        if (StringUtils.isNotEmpty(type)) {
            criteria.andTypeEqualTo(type);
        }

        activityResourcesEntityExample.setOrderByClause("cast(SORT as int) asc,UPDATE_DATE desc");
        List<ActivityResourcesEntity> consultCarouselPicEntities = activityResourcesEntityMapper.selectByExample(activityResourcesEntityExample);
        return consultCarouselPicEntities;
    }

    public VersionInfoEntity getVersion(){
        VersionInfoEntityExample versionInfoEntityExample=new VersionInfoEntityExample();
        versionInfoEntityExample.setOrderByClause("CREATE_TIME desc ");
        versionInfoEntityExample.createCriteria().andDelFlagEqualTo("0");
        List<VersionInfoEntity> versionInfoEntities = versionInfoEntityMapper.selectByExample(versionInfoEntityExample);
        if (CollectionUtil.isNotEmpty(versionInfoEntities)){
            return  versionInfoEntities.get(0);
        }else {
            return null;
        }
    }
}
